home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Sound / Documents / AudioFormats2.10 next >
Text File  |  1993-09-26  |  73KB  |  1,737 lines

  1. Subject: FAQ: Audio File Formats (version 2.10)
  2. Newsgroups: alt.binaries.sounds.misc,alt.binaries.sounds.d,comp.dsp,news.answers
  3. Followup-to: alt.binaries.sounds.d,comp.dsp
  4. Reply-to: guido@cwi.nl
  5. Approved: news-answers-request@MIT.Edu
  6.  
  7. Archive-name: audio-fmts/part1
  8. Submitted-by: Guido van Rossum <guido@cwi.nl>
  9. Version: 2.10
  10. Last-modified: 11-Jan-1993
  11.  
  12. FAQ: Audio File Formats (version 2.10)
  13. ======================================
  14.  
  15. Table of contents
  16. -----------------
  17.  
  18. Introduction
  19. Device characteristics
  20. Popular sampling rates
  21. Compression schemes
  22. Current hardware
  23. File formats
  24. File conversions
  25. Playing audio files on UNIX
  26. Playing audio files on micros
  27. The Sound Site Newsletter
  28. Posting sounds
  29.  
  30. Appendices:
  31.  
  32.   FTP access for non-internet sites
  33.   AIFF Format (Audio IFF)
  34.   The NeXT/Sun audio file format
  35.   IFF/8SVX Format
  36.   Playing sound on a PC
  37.   The EA-IFF-85 documentation
  38.   US Federal Standard 1016 availability
  39.   Creative Voice (VOC) file format
  40.   RIFF WAVE (.WAV) file format
  41.   U-LAW and A-LAW definitions
  42.   AVR File Format
  43.   
  44.  
  45. Introduction
  46. ------------
  47.  
  48. This is version 2 of this FAQ, which I started in November 1991 under
  49. the name "The audio formats guide".  I bumped the major version number
  50. since the Subject and Newsgroups headers have changed to make the
  51. subject more informative and give the guide a wider audience.  I also
  52. added a Table of contents section at the top.
  53.  
  54. I am posting this about once a fortnight, either unchanged (just to
  55. inform new readers), or updated (if I learn more or when new hardware
  56. or software becomes popular).  I post to alt.binaries.sounds.{misc,d}
  57. and to comp.dsp, for maximal coverage of people interested in audio,
  58. and to news.answers, for easy reference.
  59.  
  60. A companion posting with subject "Change to: ..." is occasionally
  61. posted listing the diffs between a new version and the last.  This is
  62. not reposted, and it is suppressed when the diffs are bigger than the
  63. new version.
  64.  
  65. NEWSFLASH: This FAQ is now also available in distributed hypertext
  66. form!  If you have a WWW browser and direct Internet access you can
  67. point it to "http://voorn.cwi.nl/audio-formats/a00.html".  (WWW is the
  68. CERN World-Wide Web initiative; for more info, telnet or ftp to
  69. info.cern.ch.)
  70.  
  71. Send updates, comments and questions to <guido@cwi.nl>; flames to
  72. /dev/null.
  73.  
  74. I'd like to thank everyone who sent me mail with updates for previous
  75. versions.  The list of names is really too long to list you all...
  76.  
  77.   --Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
  78.   "Lobster thermidor aux crevettes with a mornay sauce garnished with
  79.   truffle pate, brandy and a fried egg on top and spam"
  80.  
  81.  
  82. Device characteristics
  83. ----------------------
  84.  
  85. In this text, I will only use the term "sample" to refer to a single
  86. output value from an A/D converter, i.e., a small integer number
  87. (usually 8 or 16 bits).
  88.  
  89. Audio data is characterized by the following parameters, which
  90. correspond to settings of the A/D converter when the data was
  91. recorded.  Naturally, the same settings must be used to play the data.
  92.  
  93. - sampling rate (in samples per second), e.g. 8000 or 44100
  94.  
  95. - number of bits per sample, e.g. 8 or 16
  96.  
  97. - number of channels (1 for mono, 2 for stereo, etc.)
  98.  
  99. Approximate sampling rates are often quoted in Hz or kHz ([kilo-]
  100. Hertz), however, the politically correct term is samples per second
  101. (samples/sec).  Sampling rates are always measured per channel, so for
  102. stereo data recorded at 8000 samples/sec, there are actually 16000
  103. samples in a second.  I will sometimes write 8 k as a shorthand for
  104. 8000 samples/sec.
  105.  
  106. Multi-channel samples are generally interleaved on a frame-by-frame
  107. basis: if there are N channels, the data is a sequence of frames,
  108. where each frame contains N samples, one from each channel.  (Thus,
  109. the sampling rate is really the number of *frames* per second.)  For
  110. stereo, the left channel usually comes first.
  111.  
  112. The specification of the number of bits for U-LAW (pronounced mu-law
  113. -- the u really stands for the Greek letter mu) samples is somewhat
  114. problematic.  These samples are logarithmically encoded in 8 bits,
  115. like a tiny floating point number; however, their dynamic range is
  116. that of 14 bit linear data.  Source for converting to/from U-LAW
  117. (written by Jef Poskanzer) is distributed as part of the SOX package
  118. mentioned below; it can easily be ripped apart to serve in other
  119. applications.  The official definition is the CCITT standard G.711.
  120.  
  121. There exists another encoding similar to U-LAW, called A-LAW, which
  122. is used as a European telephony standard.  There is less support for
  123. it in UNIX workstations.
  124.  
  125. (See the Appendix for some formulae describing U-LAW and A-LAW.)
  126.  
  127.  
  128. Popular sampling rates
  129. ----------------------
  130.  
  131. Some sampling rates are more popular than others, for various reasons.
  132. Some recording hardware is restricted to (approximations of) some of
  133. these rates, some playback hardware has direct support for some.  The
  134. popularity of divisors of common rates can be explained by the
  135. simplicity of clock frequency dividing circuits :-).
  136.  
  137. Samples/sec     Description
  138.  
  139. 5500            One fourth of the Mac sampling rate (rarely seen).
  140.  
  141. 7333            One third of the Mac sampling rate (rarely seen).
  142.  
  143. 8000            Exactly 8000 samples/sec is a telephony standard that
  144.                 goes together with U-LAW (and also A-LAW) encoding.
  145.                 Some systems use an slightly different rate; in
  146.                 particular, the NeXT workstation uses 8012.8210513,
  147.                 apparently the rate used by Telco CODECs.
  148.  
  149. 11 k            Either 11025, a quarter of the CD sampling rate,
  150.                 or half the Mac sampling rate (perhaps the most
  151.                 popular rate on the Mac).
  152.  
  153. 16000           Used by, e.g. the G.722 compression standard.
  154.  
  155. 18.9 k          CD-ROM/XA standard.
  156.  
  157. 22 k            Either 22050, half the CD sampling rate, or the Mac
  158.                 rate; the latter is precisely 22254.545454545454 but
  159.                 usually misquoted as 22000.  (Historical note:
  160.                 22254.5454... was the horizontal scan rate of the
  161.                 original 128k Mac.)
  162.  
  163. 32000           Used in digital radio, NICAM (Nearly-Instantaneous
  164.                 Companded Audio Multiplex [IBA/BREMA/BBC]) and other
  165.                 TV work, at least in the UK; also long play DAT and
  166.                 Japanese HDTV.
  167.  
  168. 37.8 k          CD-ROM/XA standard for higher quality.
  169.  
  170. 44056           This weird rate is used by professional audio
  171.                 equipment to fit an integral number of samples in a
  172.                 video frame.
  173.  
  174. 44100           The CD sampling rate.  (DAT players recording
  175.                 digitally from CD also use this rate.)
  176.  
  177. 48000           The DAT (Digital Audio Tape) sampling rate for
  178.                 domestic use.
  179.  
  180. Files samples on SoundBlaster hardware have sampling rates that are
  181. divisors of 1000000.
  182.  
  183. While professinal musicians disagree, most people don't have a problem
  184. if recorded sound is played at a slightly different rate, say, 1-2%.
  185. On the other hand, if recorded data is being fed into a playback
  186. device in real time (say, over a network), even the smallest
  187. difference in sampling rate can frustrate the buffering scheme used...
  188.  
  189. There may be an emerging tendency to standardize on only a few
  190. sampling rates and encoding styles, even if the file formats may
  191. differ.  The suggested rates and styles are:
  192.  
  193.     rate (samp/sec) style mono/stereo
  194.  
  195.     8000 8-bit U-LAW mono
  196.     22050 8-bit linear unsigned mono and stereo
  197.     44100 16-bit linear signed mono and stereo
  198.  
  199.  
  200. Compression schemes
  201. -------------------
  202.  
  203. Strange though it seems, audio data is remarkably hard to compress
  204. effectively.  For 8-bit data, a Huffman encoding of the deltas between
  205. successive samples is relatively successful.  For 16-bit data,
  206. companies like Sony and Philips have spent millions to develop
  207. proprietary schemes.
  208.  
  209. Public standards for voice compression are slowly gaining popularity,
  210. e.g. CCITT G.721 and G.723 (ADPCM at 32 and 24 kbits/sec).  (ADPCM ==
  211. Adaptive Delta Pulse Code Modulation.)  Free source code for a *fast*
  212. 32 kbits/sec ADPCM algorithm is available by ftp from ftp.cwi.nl as
  213. /pub/adpcm.shar.  (** NOTE: if you are using v1.0, you should get
  214. v1.1, released 17-Dec-1992, which fixes a serious bug -- the quality
  215. of v1.1 is claimed to be better than uLAW **)
  216.  
  217. There are also two US federal standards, 1016 (Code excited linear
  218. prediction (CELP), 4800 bits/s) and 1015 (LPC-10E, 2400 bits/s).  See
  219. also the appendix for 1016.
  220.  
  221. (Note that U-LAW and silence detection can also be considered
  222. compression schemes.)
  223.  
  224. Here's a note about audio codings by Van Jacobson <van@ee.lbl.gov>:
  225. Several people used the words "LPC" and "CELP" interchangably.  They
  226. are very different.  An LPC (Linear Predictive Coding) coder fits
  227. speech to a simple, analytic model of the vocal tract, then throws
  228. away the speech & ships the parameters of the best-fit model.  An LPC
  229. decoder uses those parameters to generate synthetic speech that is
  230. usually more-or-less similar to the original.  The result is
  231. intelligible but sounds like a machine is talking.  A CELP (Code
  232. Excited Linear Predictor) coder does the same LPC modeling but then
  233. computes the errors between the original speech & the synthetic model
  234. and transmits both model parameters and a very compressed
  235. representation of the errors (the compressed representation is an
  236. index into a 'code book' shared between coders & decoders -- this is
  237. why it's called "Code Excited").  A CELP coder does much more work
  238. than an LPC coder (usually about an order of magnitude more) but the
  239. result is much higher quality speech: The FIPS-1016 CELP we're working
  240. on is essentially the same quality as the 32Kb/s ADPCM coder but uses
  241. only 4.8Kb/s (the same as the LPC coder).
  242.  
  243. Finally, the comp.compression FAQ has some text on the 6:1 audio
  244. compression scheme used by MPEG (a video compression standard-to-be).
  245. It's interesting to note that video compression reaches much higher
  246. ratios (like 26:1).  This FAQ is ftp'able from rtfm.mit.edu
  247. [18.72.1.58] in directory /pub/usenet/news.answers/compression-faq,
  248. files part1 and part2.
  249.  
  250. Comp.compression also carries a regular posting "How to uncompress
  251. anything" by David Lemson <lemson@uiuc.edu>, which (tersely) hints on
  252. which program you need to uncompress a file whose name ends in .<foo>
  253. for almost any conceivable <foo>.  Ftp'able from ftp.cso.uiuc.edu
  254. (128.174.5.59) in the directory /doc/pcnet as the file compression.
  255.  
  256.  
  257. Current hardware
  258. ----------------
  259.  
  260. I am aware of the following computer systems that can play back and
  261. (sometimes) record audio data, with their characteristics.  Note that
  262. for most systems you can also buy "professional" sampling hardware,
  263. which supports much better quality, e.g. >= 44.1 k 16 bits stereo.
  264. The characteristics listed here are a rough estimate of the
  265. capabilities of the basic hardware only (and even here I am on thin
  266. ice, with systems becoming ever more powerful).
  267.  
  268. machine             bits            max sampling rate    #output channels
  269.  
  270. Mac                 8               22k                  1
  271. Apple IIgs          8               32k / >70k           8(st)
  272. PC/Soundblaster v1  8               13k / 22k            1
  273. PC/Soundblaster v2  8               15k / 44.1k          1
  274. PC/PAS-16           16              44.1k                ?(st)
  275. Atari ST            8               22k                  1
  276. Atari STe,TT        8               50k                  2
  277. Atari Falcon 030    16              50k                  8(st)
  278. Amiga               8               ~29k                 4(st)
  279. Sun Sparc           U-LAW           8k                   1
  280. Sun Sparcst. 10     U-LAW,8,16      48k                  1(st)
  281. NeXT                U-LAW,8,16      44.1k                1(st)
  282. SGI Indigo          8,16            48k                  4(st)
  283. Acorn Archimedes    ~U-LAW          ~180k                8(st)
  284. Sony RISC-NEWS      8, 16           37.8k                ?(st)
  285. VAXstation 4000     U-LAW           8k                   1
  286. Tandy 1000/*L*      8               22k                  3
  287. HP9000/705,710,425e U,A-LAW,8       8k                   1
  288.  
  289. 4(st) means "four voices, stereo"; sampling rates xx/yy are
  290. different recording/playback rates; *L* is any type with 'L' in it.
  291.  
  292. All these machines can play back sound without additional hardware,
  293. although the needed software is not always standard; only the Sun,
  294. NeXT and SGI come with standard sampling hardware (the NeXT only
  295. samples U-LAW at 8000 samples/sec from the built-in microphone port;
  296. you need a separate board for other rates).
  297.  
  298. The new VAXstation 4000 (VLC and model 60) series lets you PLAY audio
  299. (.au) files, and the package DECsound will let you do the recording.
  300. In fact, DECsound is given away free with Motif 1.1 and supports the
  301. VAXstation, Sun SPARCstation, DECvoice, and XMedia audio devices.  Sun
  302. sound files work without change.
  303.  
  304. The SGI Personal IRIS 4D/30 and 4D/35 have the same capabilities as
  305. the Indigo.
  306.  
  307. The new Apple Macs have more powerful audio hardware; the latest
  308. models have built-in microphones.
  309.  
  310. Software exists for the PC that can play sound on its 1-bit speaker
  311. using pulse width modulation (see appendix); the Soundblaster board
  312. records at rates up to 13 k and plays back up to 22 k (weird
  313. combination, but that's the way it is).
  314.  
  315. Here's some info about the newest Atari machine, the Falcon030.  This
  316. machine has stereo 16 bit CODECs and a 32 MHz Motorola 56001 that can
  317. handle 8 channels of 16 bit audio, up to 50 khz/channel with
  318. simultaneous playback and record.  The Falcon DMA sound engine is also
  319. compatible with the 8 bit stereo DMA used on the STe and TT. All of
  320. these systems use signed data.
  321.  
  322. On the NeXT, the Motorola 56001 DSP chip is programmable and you can
  323. (in principle) do what you want.  The SGI uses the same DSP chip but
  324. it can't be programmed by users -- SGI prefers to offer it as a shared
  325. system resource to multiple applications, thus enabling developers to
  326. program audio with their Audio Library and avoid code modifications
  327. for execution on future machines with different audio hardware, i.e. a
  328. different DSP.
  329.  
  330. The Amiga also has a 6-bit volume, which can be used to produce
  331. something like a 14-bit output for each voice.  The hardware can also
  332. use one of each voice-pair to modulate the other in FM (period) or AM
  333. (volume, 6-bits).
  334.  
  335. The Acorn Archimedes uses a variation on U-LAW with the bit order
  336. reversed and the sign bit in bit 0.  Being a 'minority' architecture,
  337. Arc owners are quite adept at converting sound/image formats from
  338. other machines, and it is unlikely that you'll ever encounter sound in
  339. one of the Arc's own formats (there are several).
  340.  
  341. CD-I machines form a special category.  The following formats are used:
  342.  
  343.      - PCM 44.1 kHz standard CD format
  344.      - ADPCM - Addaptive Delta PCM
  345.        - Level A 37.8 kHz 8-bit
  346.        - Level B 37.8 kHz 4-bit
  347.        - Level C 18.9 kHz 4-bit
  348.  
  349.  
  350. File formats
  351. ------------
  352.  
  353. Historically, almost every type of machine used its own file format
  354. for audio data, but some file formats are more generally applicable,
  355. and in general it is possible to define conversions between almost any
  356. pair of file formats -- sometimes losing information, however.
  357.  
  358. File formats are a separate issue from device characteristics.  There
  359. are two types of file formats: self-describing formats, where the
  360. device parameters and encoding are made explicit in some form of
  361. header, and "raw" formats, where the device parameters and encoding
  362. are fixed.
  363.  
  364. Self-describing file formats generally define a family of data
  365. encodings, where a header fields indicates the particular encoding
  366. variant used.  Headerless formats define a single encoding and usually
  367. allows no variation in device parameters (except sometimes sampling
  368. rate, which can be a pain to figure out other than by listening to the
  369. sample).
  370.  
  371. The header of self-describing formats contains the parameters of the
  372. sampling device and sometimes other information (e.g. a
  373. human-readable description of the sound, or a copyright notice).  Most
  374. headers begin with a simple "magic word".  (Some formats do not simply
  375. define a header format, but may contain chunks of data intermingled
  376. with chunks of encoding info.)  The data encoding defines how the
  377. actual samples are stored in the file, e.g. signed or unsigned, as
  378. bytes or short integers, in little-endian or big-endian byte order,
  379. etc.  Strictly spoken, channel interleaving is also part of the
  380. encoding, although so far I have seen little variation in this area.
  381.  
  382. Some file formats apply some kind of compression to the data, e.g.
  383. Huffman encoding, or simple silence deletion.
  384.  
  385. Here's an overview of popular file formats.
  386.  
  387.         Self-describing file formats
  388.         ----------------------------
  389.  
  390. extension, name   origin          variable parameters (fixed; comments)
  391.  
  392. .au or .snd       NeXT, Sun       rate, #channels, encoding, info string
  393. .aif(f), AIFF     Apple, SGI      rate, #channels, sample width, lots of info
  394. .aif(f), AIFC     Apple, SGI      same (extension of AIFF with compression)
  395. .iff, IFF/8SVX    Amiga           rate, #channels, instrument info (8 bits)
  396. .voc              Soundblaster    rate (8 bits/1 ch; can use silence deletion)
  397. .wav, WAVE        Microsoft       rate, #channels, sample width, lots of info
  398. .sf               IRCAM           rate, #channels, encoding, info
  399. none, HCOM        Mac             rate (8 bits/1 ch; uses Huffman compression)
  400. none, MIME        Internet        (see below)
  401. .mod or .nst      Amiga           (see below)
  402.  
  403. Note that the filename extension ".snd" is ambiguous: it can be either
  404. the self-describing NeXT format or the headerless Mac/PC format, or
  405. even a headerless Amiga format.
  406.  
  407. I know nothing for sure about the origin of HCOM files, only that
  408. there are a lot of them floating around on our system and probably at
  409. FTP sites over the world.  The filenames usually don't have a ".hcom"
  410. extension, but this is what SOX (see below) uses.  The file format
  411. recognized by SOX includes a MacBinary header, where the file
  412. type field is "FSSD".  The data fork begins with the magic word "HCOM"
  413. and contains Huffman compressed data; after decompression it it is 8
  414. bits unsigned data.
  415.  
  416. IFF/8SVX allows for amplitude contours for sounds (attack/decay/etc).
  417. Compression is optional (and extensible); volume is variable; author,
  418. notes and copyright properties; etc.
  419.  
  420. AIFF, AIFC and WAVE are similar in spirit but allow more freedom in
  421. encoding style (other than 8 bit/sample), amongst others.
  422.  
  423. There are other sound formats in use on Amiga by digitizers and music
  424. programs, such as IFF/SMUS.
  425.  
  426. Appendices describes the NeXT and VOC formats; pointers to more info
  427. about AIFF, AIFC, 8SVX and WAVE (which are too complex to describe
  428. here) are also in appendices.
  429.  
  430. DEC systems (e.g. DECstation 5000) use a variant of the NeXT format
  431. that uses little-endian encoding and has a different magic number
  432. (0x0064732E in little-endian encoding).
  433.  
  434. Standard file formats used in the CD-I world are IFF but on the disc
  435. they're in realtime files.
  436.  
  437. An interesting "interchange format" for audio data is described in the
  438. proposed Internet Standard "MIME", which describes a family of
  439. transport encodings and structuring devices for electronic mail.  This
  440. is an extensible format, and initially standardizes a type of audio
  441. data dubbed "audio/basic", which is 8-bit U-LAW data sampled at 8000
  442. samples/sec.
  443.  
  444. Finally, a somewhat different but popular format are "MOD" files,
  445. usually with extension ".mod" or ".nst" (they can also have a prefix
  446. of "mod.").  This originated at the Amiga but players now exist for
  447. many platforms.  MOD files are music files containing 2 parts: (1) a
  448. bank of digitized samples; (2) sequencing information describing how
  449. and when to play the samples.  See the appendix "The Amiga MOD Format"
  450. for a description of this file format.
  451.  
  452.         Headerless file formats
  453.         -----------------------
  454.  
  455. extension       origin          parameters
  456. or name
  457.  
  458. .snd, .fssd     Mac, PC         variable rate, 1 channel, 8 bits unsigned
  459. .ul             US telephony    8 k, 1 channel, 8 bit "U-LAW" encoding
  460. .snd?           Amiga           variable rate, 1 channel, 8 bits signed
  461.  
  462. It is usually easy to distinguish 8-bit signed formats from unsigned
  463. by looking at the beginning of the data with 'od -b <file | head';
  464. since most sounds start with a little bit of silence containing small
  465. amounts of background noise, the signed formats will have an abundance
  466. of bytes with values 0376, 0377, 0, 1, 2, while the unsigned formats
  467. will have 0176, 0177, 0200, 0201, 0202 instead.  (Using "od -c" will
  468. also show any headers that are tacked in front of the file.)
  469.  
  470. The Apple IIgs records raw data in the same format as the Mac, but
  471. uses a 0 byte as a terminator; samples with value 0 are replaced by 1.
  472.  
  473.  
  474. File conversions
  475. ----------------
  476.  
  477.     SOX
  478.     ---
  479.  
  480. The most versatile tool for converting between various audio formats
  481. is SOX ("Sound Exchange").  It can read and write various types of
  482. audio files, and optionally applies some special effects (e.g. echo,
  483. channel averaging, or rate conversion).
  484.  
  485. SOX recognizes all filename extensions listed above except ".snd",
  486. which would be ambiguous anyway, and ".wav" (but there's a patch, see
  487. below).  Use type ".au" for NeXT ".snd" files.  Mac and PC ".snd"
  488. files are completely described by these parameters:
  489.  
  490.       -t raw -b -u -r 11000
  491.  
  492. (or -r 22000 or -r 7333 or -r 5500; 11000 seems to be the most common
  493. rate).
  494.  
  495. The source for SOX, version 5, was posted to alt.sources, and should
  496. be widely archived.  To save you the trouble of hunting it down, it
  497. can be gotten by anonymous ftp from wuarchive.wustl.edu, in the
  498. directory usenet/alt.sources/articles, files 5581.Z through 5585.Z.
  499. (These files are compressed news articles containing shar files, if
  500. you hadn't guessed.)  I am sure many sites have similar archives, I'm
  501. just listing one that I know of and which carries a lot of this kind
  502. of stuff.  (Also see the appendix if you don't have Internet access.)
  503.  
  504. A compressed tar file containing the same version of SOX is available
  505. by anonymous ftp from ftp.cwi.nl [192.16.184.180], in /pub/sox*.tar.Z.
  506. You may be able to locate a nearer version using archie!
  507.  
  508. Ports of SOX:
  509.  
  510. - The source as posted should compile on any UNIX system with 4-byte
  511.   integers.
  512.  
  513. - A PC version is available by ftp from ftp.cwi.nl (see above) as
  514.   pub/sox4*.zip; also available from the garbo mail server.
  515.  
  516. - The latest Amiga SOX (corresponding to version 5) is available via
  517.   anonymous ftp to wuarchive.wustl.edu, files
  518.   systems/amiga/audio/utils/amisox*.  (See below for a non-SOX
  519.   solution.)
  520.  
  521. SOX usage hints:
  522.  
  523. - Often, the filename extension of sound files posted on the net is
  524.   wrong.  Don't give up, try a few other possibilities using the
  525.   "-t <type>" option.  Remember that the most common file type is
  526.   unsigned bytes, which can be indicated with "-t ub".  You'll have to
  527.   guess the proper sampling rate, but often it's 11k or 22k.
  528.  
  529. - In particular, with SOX version 4 (or earlier), you have to
  530.   specify "-t 8svx" for files with an .iff extension.
  531.  
  532. - When converting linear samples to U-LAW using the .au type for the
  533.   output file, you must specify "-U" for the output file, otherwise
  534.   you will end up with a file containing a NeXT/Sun header but linear
  535.   samples -- only the NeXT will play such files correctly.  Also, you
  536.   must explicitly specify an output sampling rate with "-r 8000".
  537.   (This may seem fixed for most cases in version 5, but it is still
  538.   occasionally necessary, so I'm keeping this warning in.)
  539.  
  540.         Sun Sparc
  541.         ---------
  542.  
  543. On Sun Sparcs, starting at SunOS 4.1, a program "raw2audio" is
  544. provided by Sun (in /usr/demo/SOUND -- see below) which takes a raw
  545. U-LAW file and turns it into a ".au" file by prefixing it with an
  546. appropriate header.
  547.  
  548.         NeXT
  549.         ----
  550.  
  551. On NeXTs, you can usually rename .au files to .snd and it'll work like
  552. a charm, but some .au files lack header info that the NeXT needs.
  553. This can be fixed by using sndconvert:
  554.  
  555.         sndconvert -c 1 -f 1 -s 8012.8210513 -o nextfile.snd sunfile.au
  556.  
  557.         SGI Indigo and Personal IRIS
  558.         ----------------------------
  559.  
  560. SGI supports "soundfiler" (in /usr/sbin), a program similar in
  561. spirit to SOX but with a GUI.  Soundfiler plays aiff, aifc, NeXT/Sun
  562. and .wav formats.  It can do conversions between any of these formats
  563. and to and from raw formats including mulaw.  It also does sample rate
  564. conversions.
  565.  
  566. Three shell commands are also provided that give the same functionality:
  567. "sfplay", "sfconvert", and "aifcresample" (all in /usr/sbin).
  568.  
  569.         Amiga
  570.         -----
  571.  
  572. Mike Cramer's SoundZAP can do no effects except rate change and it
  573. only does conversions to IFF, but it is generally much faster than
  574. SOX.  (Ftp'able from the same directory as amisox above.)
  575.  
  576.         Tandy
  577.         -----
  578.  
  579. The Tandy 1000 uses a (proprietary?) compressed format.  There is a
  580. PD Mac to Tandy conversion program called CONVERT.
  581.  
  582.  
  583. Playing audio files on UNIX
  584. ---------------------------
  585.  
  586. The commands needed to play an audio file depend on the file format
  587. and the available hardware and software.  Most systems can only
  588. directly play sound in their native format; use a conversion program
  589. (see above) to play other formats.
  590.  
  591.         Sun Sparcstation running SunOS 4.x
  592.         ----------------------------------
  593.  
  594. Raw U-LAW files can be played using "cat file >/dev/audio".
  595.  
  596. A whole package for dealing with ".au" files is provided by Sun on an
  597. experimental basis, in /usr/demo/SOUND.  You may have to compile the
  598. programs first.  (If you can't find this directory, either you are not
  599. running SunOS 4.1 yet, or your system administrator hasn't installed
  600. it -- go ask him for it, not me!)  The program "play" in this
  601. directory recognizes all files in Sun/NeXT format, but a SS 1 or 2 can
  602. play only those using U-LAW encoding at 8 k -- the SS 10 hardware
  603. plays other encodings, too.
  604.  
  605. If you ca't find "play", you can also cat a ".au" file to /dev/audio,
  606. if it uses U-LAW; the header will sound like a short burst of noise
  607. but the rest of the data will sound OK (really, the only difference in
  608. this case between raw U-LAW and ".au" files is the header; the U-LAW
  609. data is exactly the same).
  610.  
  611. Finally, OpenWindows 3.0 has a full-fledged audio tool.  You can drop
  612. audio file icons into it, edit them, etc.
  613.  
  614.         Sun Sparcstation running Solaris 2.0
  615.         ------------------------------------
  616.  
  617. Under SVR4 (and hence Solaris 2.0), writing to /dev/audio from the
  618. shell is a bad idea, because the device driver will flush its queue as
  619. soon as the file is closed.  Use "audioplay" instead.  The supported
  620. formats and sampling rates are the same as above.
  621.  
  622.         NeXT
  623.         ----
  624.  
  625. On NeXT machines, the standard "sndplay" program can play all NeXT
  626. format files (this include Sun ".au" files).  It supports at least
  627. U-LAW at 8 k and 16 bits samples at 22 or 44.1 k.  It attempts
  628. on-the-fly conversions for other formats.
  629.  
  630. Sound files are also played if you double-click on them in the file
  631. browser.
  632.  
  633.         SGI Indigo and Personal IRIS
  634.         ----------------------------
  635.  
  636. On SGI Indigo and the 4D/30 and /35 Personal IRIS workstations,
  637. "WorkSpace" plays audio files in .aiff, .aifc, .au, and .wav formats if
  638. you double click them and the sampling rate is one of 8000, 11025,
  639. 16000, 22050, 32000, 44100, or 48000.  On the Personal IRIS, you need
  640. to have the audio board installed (check the output from hinv) and you
  641. must run IRIX 3.3.2 or 4.0 or higher.  These files can also be played
  642. with "soundfiler" and "sfplay".  ".aiff" and ".aifc" files at the above
  643. sampling rates can also be played with playaifc.  (All in /usr/sbin)
  644.  
  645. There is no simple /dev/audio interface on these SGI machines.  (There
  646. was one on 4D/25 machines, reading and writing signed linear 8-bit
  647. samples at rates of 8, 16 and 32 k.)
  648.  
  649. A program "playulaw" was posted as part of the "radio 2.0" release
  650. that I posted to several source groups recently; it plays raw U-LAW
  651. files on the Indigo or Personal IRIS audio hardware.
  652.  
  653.         Sony NEWS
  654.         ---------
  655.  
  656. The Sony RISC-NEWS line (NWS-3250 laptop, NWS-37xx desktop, NWS-38xx
  657. desktop w/ IOP) also has builtin sound capabilities.  You can also buy
  658. external boards for the older NEWS machines or to add extra channels
  659. to the new machines.  In the default mode (8k/8-bit), Sun .au files
  660. are directly supported (you can 'cat' .au files to /dev/sb and have
  661. them play).
  662.  
  663.         Vaxstation 4000
  664.         ---------------
  665.  
  666. ".au" files can be played by COPYING them to device "SOA0:".  This
  667. device is set up by enabling the driver SODRIVER, as described below:
  668.  
  669. DEC's sound stuff is like most other new toy.  Hardware first, THEN the
  670. software.   DEC will soon be releasing a layered product called DECsound,
  671. which will let you record, play, and (possibly) manipulate sound files.
  672. Third party product(s) have ALREADY hit the market.
  673.  
  674. Enabling SODRIVER:   (you can use the following command file)
  675.  
  676. $!---------------- cut here -------------------------------
  677. $! sound_setup.com    enable SOUND driver
  678. $ run sys$system:sysgen
  679. connect soa0 /adapter=0 /csr=%x0e00 /vector=%o304 /driver=sodriver
  680. exit
  681. $ exit
  682. $!----------------- cut here ------------------------------------
  683.  
  684. The external audio port comes with a telephone-jack-like port.   For
  685. starters, you can plug a telephone RECEIVER right into this port to
  686. hear your first sound files.   After that, you can use the adapter
  687. (that came with the VaxStation), and plug in a small set of stereo
  688. speakers (the kind you'd plug into a WALKMAN, for example), for more
  689. volume.
  690.  
  691.         Others
  692.         ------
  693.  
  694. Most other UNIX boxes don't have audio hardware and thus can't play
  695. audio data.
  696.  
  697.  
  698. Playing audio files on micros
  699. -----------------------------
  700.  
  701. Most micros have at least a speaker built in, so theoretically all you
  702. need is the right software.  Unfortunately most systems don't come
  703. bundled with sound-playing software, so there are many public domain
  704. or shareware software packages, each with their own bugs and features.
  705. Most separate sound recording hardware also comes with playing
  706. software, most of which can play sound (in the file format used by
  707. that hardware) even on machines that don't have that hardware
  708. installed.
  709.  
  710. Chris S. Craig announces the following software for PCs:
  711.  
  712. ScopeTrax       This is a complete PC sound player/editor package.  Sounds
  713.                 can be played back at ANY rate between 1kHz to 65kHz through
  714.                 the PC speaker or the Sound Blaster.  It supports several
  715.                 file formats including VOC, IFF/8SVX, raw signed and raw
  716.                 unsigned.  A separate executable is provided to convert
  717.                 .au and mu-law to raw format.  ScopeTrax requires EGA/VGA
  718.                 graphics for editing and displaying sounds on a REALTIME
  719.                 oscilloscope.  The package also includes:
  720.                       * An expanded memory player which can play sounds
  721.                         larger than 640K in size.
  722.                       * Basic (rough) sound compression/uncompression
  723.                         utilities.
  724.                       * Complete documentation.
  725.                 The package is FREEWARE!  It is available on SIMTEL in the
  726.                 PD1:[MSDOS.SOUND] directory.
  727.  
  728. One of the appendices below contains a list of more programs to play
  729. sound on the PC.
  730.  
  731. For sounds on Atari STs - programs are in the atari/sound/players
  732. directory on atari.archive.umich.edu (141.211.164.8).
  733.  
  734. Malcolm Slaney from Apple writes:
  735.  
  736.  "We do have tools to play sound back on most of our Unix hosts.  We wrote
  737.  a program called TcpPlay that lets us read a sound file on a Unix host,
  738.  open a TCP/IP connection to the Mac on my desk, and plays the file.  We
  739.  think of it as X windows for sound (at least a step in that direction.)
  740.  
  741.  This software is available for anonymous FTP from ftp.apple.com.
  742.  Look for  ~ftp/pub/TcpPlay/TcpPlay.sit.hqx.
  743.  
  744.  Finally, there are MANY tools for working with sound on the Macintosh. Three
  745.  applications that come to mind immediately are SoundEdit (formerly by
  746.  Farralon and now by MacroMind/Paracomp), Alchemy and Eric Keller's Signalyze.
  747.  There are lots of other tools available for sound editing (including some
  748.  of the QuickTime Movie tools.)"
  749.  
  750. On a Tandy 1000, sounds can be played and recorded with DeskMate Sound
  751. (SOUND.PDM), or if they not stored in compressed format, they can also
  752. be played be a program called PLAYSND.  No indication of whether
  753. PLAYSND is PD or not. It hasn't been updated since March of 89.
  754.  
  755. On the Amiga, OmniPlay by David Champion <dgc3@midway.uchicago.edu>
  756. plays (but does not convert) several sound formats.  It allows Amiga
  757. users to play IFF-8SVX, AIFF, WAV, VOC, .au, .snd, and 8 bit raw
  758. (signed, unsigned, u-law) samples.  OmniPlay is available at the
  759. following FTP sites:
  760. * wuarchive.wustl.edu in /systems/amiga/audio/sampleplayers/oplay121.lha
  761. * amiga.physik.unizh.zh in music/oplay121.lha
  762.  
  763.  
  764. The Sound Site Newsletter
  765. -------------------------
  766.  
  767. An electronic publication with lots of info about digitised sound and
  768. sound formats, albeit mostly on micros, is "The Sound Site
  769. Newsletter".  So far, 8 issues have appeared, the last in January
  770. 1992.  Issues can be ftp'ed from saffron.inset.com, directory
  771. directory pub/rogue/newsletters, or from ccb.ucsf.edu,
  772. Pub/Sound_list/Sound.Newsletters.
  773.  
  774.  
  775. Posting sounds
  776. --------------
  777.  
  778. The newsgroup alt.binaries.sounds.misc is dedicated to postings
  779. containing sound.  (Discussions related to such postings belong in
  780. alt.binaries.sounds.d.)
  781.  
  782. There is no set standard for posting sounds; uuencoded files in most
  783. popular formats are welcome, if split in parts under 50 kBytes.  To
  784. accomodate automatic decoding software (such as the ":decode" command
  785. of the nn newsreader), please place a part indicator of the form
  786. (mm/nn) at the end of your subject meaning this is number mm of a
  787. total of nn part.
  788.  
  789. It is recommended to post sounds in the format that was used for the
  790. original recording; conversions to other formats often lose
  791. information and would do people with identical hardware as the poster
  792. no favor.  For instance, convering 8-bit linear sound to U-LAW loses
  793. the lower few bits of the data, and rate changing conversions almost
  794. always add noise.  Converting from U-LAW to linear requires expansion
  795. to 16 bit samples if no information loss is allowed!
  796.  
  797. U-LAW data is best posted with a NeXT/Sun header.
  798.  
  799. If you have to post a file in a headerless format (usually 8-bit
  800. linear, like ".snd"), please add a description giving at least the
  801. sampling rate and whether the bytes are signed (zero at 0) or unsigned
  802. (zero at 0200).  However, it is highly recommended to add a header
  803. that indicates the sampling rate and encoding scheme; if necessary you
  804. can use SOX to add a header of your choice to raw data.
  805.  
  806. Compression of sound files usually isn't worth it; the standard
  807. "compress" algorithm doesn't save much when applied to sound data
  808. (typically at most 10-20 percent), and compression algorithms
  809. specifically designed for sound (e.g. NeXT's) are usually
  810. proprietary.  (See also the section "Compression schemes" earlier.)
  811.  
  812.  
  813. Appendices
  814. ==========
  815.  
  816. Here are some more detailed pieces of info that I received by e-mail.
  817. They are reproduced here virtually without much editing.
  818.  
  819. ------------------------------------------------------------------------
  820. FTP access for non-internet sites
  821. ---------------------------------
  822.  
  823. From the sci.space FAQ:
  824.  
  825.     Sites not connected to the Internet cannot use FTP directly, but
  826.     there are a few automated FTP servers which operate via email.
  827.     Send mail containing only the word HELP to ftpmail@decwrl.dec.com
  828.     or bitftp@pucc.princeton.edu, and the servers will send you
  829.     instructions on how to make requests
  830.  
  831. Also:
  832.  
  833.     FAQ lists are available by anonymous FTP from pit-manager.mit.edu
  834.     (18.72.1.58) and by email from mail-server@pit-manager.mit.edu (send
  835.     a message containing "help" for instructions about the mail server).
  836.  
  837.  
  838. ------------------------------------------------------------------------
  839. AIFF Format (Audio IFF) and AIFC
  840. --------------------------------
  841.  
  842. This format was developed by Apple for storing high-quality sampled
  843. sound and musical instrument info; it is also used by SGI and several
  844. professional audio packages (sorry, I know no names).  An extension,
  845. called AIFC or AIFF-C, supports compression (see the last item below).
  846.  
  847. I've made a BinHex'ed MacWrite version of the AIFF spec (no idea if
  848. it's the same text as mentioned below) available by anonymous ftp from
  849. ftp.cwi.nl [192.16.184.180]; the file is /pub/AudioIFF1.2.hqx.  But
  850. you may be better off with the AIFF-C specs, see below.
  851.  
  852. Mike Brindley (brindley@ece.orst.edu) writes:
  853.  
  854. "The complete AIFF spec by Steve Milne, Matt Deatherage (Apple) is
  855. available in 'AMIGA ROM Kernal Reference Manual: Devices (3rd Edition)'
  856. 1991 by Commodore-Amiga, Inc.; Addison-Wesley Publishing Co.; 
  857. ISBN 0-201-56775-X, starting on page 435 (this edition has a charcoal
  858. grey cover).  It is available in most bookstores, and soon in many
  859. good librairies."
  860.  
  861. Finally, Mark Callow writes (in comp.sys.sgi):
  862.  
  863. "I have placed a PostScript version of the AIFF-C specification on
  864. sgi.sgi.com for public ftp.  It is in the file sgi/aiff-c.9.26.91.ps.
  865.  
  866. sgi.sgi.com's internet host number is (I think) 192.48.153.1."
  867.  
  868. ------------------------------------------------------------------------
  869. The NeXT/Sun audio file format
  870. ------------------------------
  871.  
  872. Here's the complete story on the file format, from the NeXT
  873. documentation.  (Note that the "magic" number is ((int)0x2e736e64),
  874. which equals ".snd".)  Also, at the end, I've added a litte document
  875. that someone posted to the net a couple of years ago, that describes
  876. the format in a bit-by-bit fashion rather than from C.
  877.  
  878. I received this from Doug Keislar, NeXT Computer.  This is also the
  879. Sun format, except that Sun doesn't recognize as many format codes.  I
  880. added the numeric codes to the table of formats and sorted it.
  881.  
  882.  
  883. SNDSoundStruct:  How a NeXT Computer Represents Sound
  884.  
  885. The NeXT sound software defines the SNDSoundStruct structure to  
  886. represent sound.  This structure defines the soundfile and Mach-O  
  887. sound segment formats and the sound pasteboard type.  It's also used  
  888. to describe sounds in Interface Builder.  In addition, each instance  
  889. of the Sound Kit's Sound class encapsulates a SNDSoundStruct and  
  890. provides methods to access and modify its attributes.
  891.  
  892. Basic sound operations, such as playing, recording, and cut-and-paste  
  893. editing, are most easily performed by a Sound object.  In many cases,  
  894. the Sound Kit obviates the need for in-depth understanding of the  
  895. SNDSoundStruct architecture.  For example, if you simply want to  
  896. incorporate sound effects into an application, or to provide a simple  
  897. graphic sound editor (such as the one in the Mail application), you  
  898. needn't be aware of the details of the SNDSoundStruct.  However, if  
  899. you want to closely examine or manipulate sound data you should be  
  900. familiar with this structure.
  901.  
  902. The SNDSoundStruct contains a header, information that describes the  
  903. attributes of a sound, followed by the data (usually samples) that  
  904. represents the sound.  The structure is defined (in  
  905. sound/soundstruct.h) as:
  906.  
  907. typedef struct {
  908.     int magic;               /* magic number SND_MAGIC */
  909.     int dataLocation;        /* offset or pointer to the data */
  910.     int dataSize;            /* number of bytes of data */
  911.     int dataFormat;          /* the data format code */
  912.     int samplingRate;        /* the sampling rate */
  913.     int channelCount;        /* the number of channels */
  914.     char info[4];            /* optional text information */
  915. } SNDSoundStruct;
  916.  
  917.  
  918.  
  919.  
  920. SNDSoundStruct Fields
  921.  
  922.  
  923.  
  924. magic
  925.  
  926. magic is a magic number that's used to identify the structure as a  
  927. SNDSoundStruct.  Keep in mind that the structure also defines the  
  928. soundfile and Mach-O sound segment formats, so the magic number is  
  929. also used to identify these entities as containing a sound.
  930.  
  931.  
  932.  
  933.  
  934.  
  935. dataLocation
  936.  
  937. It was mentioned above that the SNDSoundStruct contains a header  
  938. followed by sound data.  In reality, the structure only contains the  
  939. header; the data itself is external to, although usually contiguous  
  940. with, the structure.  (Nonetheless, it's often useful to speak of the  
  941. SNDSoundStruct as the header and the data.)  dataLocation is used to  
  942. point to the data.  Usually, this value is an offset (in bytes) from  
  943. the beginning of the SNDSoundStruct to the first byte of sound data.   
  944. The data, in this case, immediately follows the structure, so  
  945. dataLocation can also be thought of as the size of the structure's  
  946. header.  The other use of dataLocation, as an address that locates  
  947. data that isn't contiguous with the structure, is described in  
  948. "Format Codes," below.
  949.  
  950.  
  951.  
  952.  
  953.  
  954. dataSize, dataFormat, samplingRate, and channelCount
  955.  
  956. These fields describe the sound data.
  957.  
  958. dataSize is its size in bytes (not including the size of the  
  959. SNDSoundStruct).
  960.  
  961. dataFormat is a code that identifies the type of sound.  For sampled  
  962. sounds, this is the quantization format.  However, the data can also  
  963. be instructions for synthesizing a sound on the DSP.  The codes are  
  964. listed and explained in "Format Codes," below.
  965.  
  966. samplingRate is the sampling rate (if the data is samples).  Three  
  967. sampling rates, represented as integer constants, are supported by  
  968. the hardware:
  969.  
  970. Constant        Sampling Rate (samples/sec) 
  971.  
  972. SND_RATE_CODEC  8012.821        (CODEC input)
  973. SND_RATE_LOW    22050.0 (low sampling rate output)
  974. SND_RATE_HIGH   44100.0 (high sampling rate output)
  975.  
  976. channelCount is the number of channels of sampled sound.
  977.  
  978.  
  979.  
  980.  
  981.  
  982. info
  983.  
  984. info is a NULL-terminated string that you can supply to provide a  
  985. textual description of the sound.  The size of the info field is set  
  986. when the structure is created and thereafter can't be enlarged.  It's  
  987. at least four bytes long (even if it's unused).
  988.  
  989.  
  990.  
  991.  
  992.  
  993. Format Codes
  994.  
  995. A sound's format is represented as a positive 32-bit integer.  NeXT  
  996. reserves the integers 0 through 255; you can define your own format  
  997. and represent it with an integer greater than 255.  Most of the  
  998. formats defined by NeXT describe the amplitude quantization of  
  999. sampled sound data:
  1000.  
  1001. Value   Code    Format 
  1002.  
  1003. 0       SND_FORMAT_UNSPECIFIED  unspecified format 
  1004. 1       SND_FORMAT_MULAW_8      8-bit mu-law samples
  1005. 2       SND_FORMAT_LINEAR_8     8-bit linear samples
  1006. 3       SND_FORMAT_LINEAR_16    16-bit linear samples
  1007. 4       SND_FORMAT_LINEAR_24    24-bit linear samples
  1008. 5       SND_FORMAT_LINEAR_32    32-bit linear samples
  1009. 6       SND_FORMAT_FLOAT        floating-point samples
  1010. 7       SND_FORMAT_DOUBLE       double-precision float samples
  1011. 8       SND_FORMAT_INDIRECT     fragmented sampled data
  1012. 9       SND_FORMAT_NESTED       ?
  1013. 10      SND_FORMAT_DSP_CORE     DSP program
  1014. 11      SND_FORMAT_DSP_DATA_8   8-bit fixed-point samples
  1015. 12      SND_FORMAT_DSP_DATA_16  16-bit fixed-point samples
  1016. 13      SND_FORMAT_DSP_DATA_24  24-bit fixed-point samples
  1017. 14      SND_FORMAT_DSP_DATA_32  32-bit fixed-point samples
  1018. 15      ?
  1019. 16      SND_FORMAT_DISPLAY      non-audio display data
  1020. 17      SND_FORMAT_MULAW_SQUELCH        ?
  1021. 18      SND_FORMAT_EMPHASIZED   16-bit linear with emphasis
  1022. 19      SND_FORMAT_COMPRESSED   16-bit linear with compression
  1023. 20      SND_FORMAT_COMPRESSED_EMPHASIZED        A combination of the two above
  1024. 21      SND_FORMAT_DSP_COMMANDS Music Kit DSP commands
  1025. 22      SND_FORMAT_DSP_COMMANDS_SAMPLES         ?
  1026.  
  1027.  
  1028. Most formats identify different sizes and types of  
  1029. sampled data.  Some deserve special note:  
  1030.  
  1031.  
  1032. --      SND_FORMAT_DSP_CORE format contains data that represents a  
  1033. loadable DSP core program.  Sounds in this format are required by the  
  1034. SNDBootDSP() and SNDRunDSP() functions.  You create a  
  1035. SND_FORMAT_DSP_CORE sound by reading a DSP load file (extension  
  1036. ".lod") with the SNDReadDSPfile() function.
  1037.  
  1038. --      SND_FORMAT_DSP_COMMANDS is used to distinguish sounds that  
  1039. contain DSP commands created by the Music Kit.  Sounds in this format  
  1040. can only be created through the Music Kit's Orchestra class, but can  
  1041. be played back through the SNDStartPlaying() function.
  1042.  
  1043. --      SND_FORMAT_DISPLAY format is used by the Sound Kit's  
  1044. SoundView class.  Such sounds can't be played.  
  1045.  
  1046.  
  1047. --      SND_FORMAT_INDIRECT indicates data that has become  
  1048. fragmented, as described in a separate section, below.  
  1049.  
  1050.  
  1051. --      SND_FORMAT_UNSPECIFIED is used for unrecognized formats.
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057. Fragmented Sound Data
  1058.  
  1059. Sound data is usually stored in a contiguous block of memory.   
  1060. However, when sampled sound data is edited (such that a portion of  
  1061. the sound is deleted or a portion inserted), the data may become  
  1062. discontiguous, or fragmented.  Each fragment of data is given its own  
  1063. SNDSoundStruct header; thus, each fragment becomes a separate  
  1064. SNDSoundStruct structure.  The addresses of these new structures are  
  1065. collected into a contiguous, NULL-terminated block; the dataLocation  
  1066. field of the original SNDSoundStruct is set to the address of this  
  1067. block, while the original format, sampling rate, and channel count  
  1068. are copied into the new SNDSoundStructs.  
  1069.  
  1070.  
  1071. Fragmentation serves one purpose:  It avoids the high cost of moving  
  1072. data when the sound is edited.  Playback of a fragmented sound is  
  1073. transparent-you never need to know whether the sound is fragmented  
  1074. before playing it.  However, playback of a heavily fragmented sound  
  1075. is less efficient than that of a contiguous sound.  The  
  1076. SNDCompactSamples() C function can be used to compact fragmented  
  1077. sound data.
  1078.  
  1079. Sampled sound data is naturally unfragmented.  A sound that's freshly  
  1080. recorded or retrieved from a soundfile, the Mach-O segment, or the  
  1081. pasteboard won't be fragmented.  Keep in mind that only sampled data  
  1082. can become fragmented.
  1083.  
  1084.  
  1085.  
  1086. _________________________
  1087. >From mentor.cc.purdue.edu!purdue!decwrl!ucbvax!ziploc!eps Wed Apr  4  
  1088. 23:56:23 EST 1990
  1089. Article 5779 of comp.sys.next:
  1090. Path: mentor.cc.purdue.edu!purdue!decwrl!ucbvax!ziploc!eps
  1091. >From: eps@toaster.SFSU.EDU (Eric P. Scott)
  1092. Newsgroups: comp.sys.next
  1093. Subject: Re: Format of NeXT sndfile headers?
  1094. Message-ID: <445@toaster.SFSU.EDU>
  1095. Date: 31 Mar 90 21:36:17 GMT
  1096. References: <14978@phoenix.Princeton.EDU>
  1097. Reply-To: eps@cs.SFSU.EDU (Eric P. Scott)
  1098. Organization: San Francisco State University
  1099. Lines: 42
  1100.  
  1101. In article <14978@phoenix.Princeton.EDU>
  1102.         bskendig@phoenix.Princeton.EDU (Brian Kendig) writes:
  1103. >I'd like to take a program I have that converts Macintosh sound  
  1104. files
  1105. >to NeXT sndfiles and polish it up a bit to go the other direction as
  1106. >well.
  1107.  
  1108. Two people have already submitted programs that do this
  1109. (Christopher Lane and Robert Hood); check the various
  1110. NeXT archive sites.
  1111.  
  1112. >       Could someone please give me the format of a NeXT sndfile
  1113. >header?
  1114.  
  1115. "big-endian"
  1116.         0       1       2       3
  1117.         +-------+-------+-------+-------+
  1118. 0       | 0x2e  | 0x73  | 0x6e  | 0x64  |       "magic" number
  1119.         +-------+-------+-------+-------+
  1120. 4       |                               |       data location
  1121.         +-------+-------+-------+-------+
  1122. 8       |                               |       data size
  1123.         +-------+-------+-------+-------+
  1124. 12      |                               |       data format (enum)
  1125.         +-------+-------+-------+-------+
  1126. 16      |                               |       sampling rate (int)
  1127.         +-------+-------+-------+-------+
  1128. 20      |                               |       channel count
  1129.         +-------+-------+-------+-------+
  1130. 24      |       |       |       |       |       (optional) info  
  1131. string
  1132.  
  1133. 28 = minimum value for data location
  1134.  
  1135. data format values can be found in /usr/include/sound/soundstruct.h
  1136.  
  1137. Most common combinations:
  1138.  
  1139.          sampling  channel    data
  1140.              rate    count  format              
  1141. voice file   8012        1       1 =  8-bit mu-law
  1142. system beep 22050        2       3 = 16-bit linear
  1143. CD-quality  44100        2       3 = 16-bit linear
  1144.  
  1145. ------------------------------------------------------------------------
  1146. IFF/8SVX Format
  1147. ---------------
  1148.  
  1149. Newsgroups: alt.binaries.sounds.d,alt.sex.sounds
  1150. Subject: Format of the IFF header (Amiga sounds)
  1151. Message-ID: <2509@tardis.Tymnet.COM>
  1152. From: jms@tardis.Tymnet.COM (Joe Smith)
  1153. Date: 23 Oct 91 23:54:38 GMT
  1154. Followup-To: alt.binaries.sounds.d
  1155. Organization: BT North America (Tymnet)
  1156.  
  1157. The first 12 bytes of an IFF file are used to distinguish between an Amiga
  1158. picture (FORM-ILBM), an Amiga sound sample (FORM-8SVX), or other file
  1159. conforming to the IFF specification.  The middle 4 bytes is the count of
  1160. bytes that follow the "FORM" and byte count longwords.  (Numbers are stored
  1161. in M68000 form, high order byte first.)
  1162.  
  1163.                 ------------------------------------------
  1164.  
  1165. FutureSound audio file, 15000 samples at 10.000KHz, file is 15048 bytes long.
  1166.  
  1167. 0000: 464F524D 00003AC0 38535658 56484452    FORM..:.8SVXVHDR
  1168.       F O R M     15040 8 S V X  V H D R
  1169. 0010: 00000014 00003A98 00000000 00000000    ......:.........
  1170.             20    15000        0        0
  1171. 0020: 27100100 00010000 424F4459 00003A98    '.......BODY..:.
  1172.      10000 1 0    1.0   B O D Y     15000
  1173.  
  1174. 0000000..03 = "FORM", identifies this as an IFF format file.
  1175. FORM+00..03 (ULONG) = number of bytes that follow.  (Unsigned long int.)
  1176. FORM+03..07 = "8SVX", identifies this as an 8-bit sampled voice.
  1177.  
  1178. ????+00..03 = "VHDR", Voice8Header, describes the parameters for the BODY.
  1179. VHDR+00..03 (ULONG) = number of bytes to follow. 
  1180. VHDR+04..07 (ULONG) = samples in the high octave 1-shot part.
  1181. VHDR+08..0B (ULONG) = samples in the high octave repeat part.
  1182. VHDR+0C..0F (ULONG) = samples per cycle in high octave (if repeating), else 0.
  1183. VHDR+10..11 (UWORD) = samples per second.  (Unsigned 16-bit quantity.)
  1184. VHDR+12     (UBYTE) = number of octaves of waveforms in sample.
  1185. VHDR+13     (UBYTE) = data compression (0=none, 1=Fibonacci-delta encoding).
  1186. VHDR+14..17 (FIXED) = volume.  (The number 65536 means 1.0 or full volume.)
  1187.  
  1188. ????+00..03 = "BODY", identifies the start of the audio data.
  1189. BODY+00..03 (ULONG) = number of bytes to follow.
  1190. BODY+04..NNNNN      = Data, signed bytes, from -128 to +127.
  1191.  
  1192. 0030: 04030201 02030303 04050605 05060605
  1193. 0040: 06080806 07060505 04020202 01FF0000
  1194. 0050: 00000000 FF00FFFF FFFEFDFD FDFEFFFF
  1195. 0060: FDFDFF00 00FFFFFF 00000000 00FFFF00
  1196. 0070: 00000000 00FF0000 00FFFEFF 00000000
  1197. 0080: 00010000 000101FF FF0000FE FEFFFFFE
  1198. 0090: FDFDFEFD FDFFFFFC FDFEFDFD FEFFFEFE
  1199. 00A0: FFFEFEFE FEFEFEFF FFFFFEFF 00FFFF01
  1200.  
  1201. This small section of the audio sample shows the number ranging from -5 (0xFD)
  1202. to +8 (0x08).  Warning: Do not assume that the BODY starts 48 bytes into the
  1203. file.  In addition to "VHDR", chunks labeled "NAME", "AUTH", "ANNO", or 
  1204. "(c) " may be present, and may be in any order.  You will have to check the
  1205. byte count in each chunk to determine how many bytes to skip.
  1206.  
  1207. ------------------------------------------------------------------------
  1208. Playing sound on a PC
  1209. ---------------------
  1210.  
  1211. From: Eric A Rasmussen
  1212.  
  1213. Any turbo PC (8088 at 8 Mhz or greater)/286/386/486/etc. can produce a quality
  1214. playback of single channel 8 bit sounds on the internal (1 bit, 1 channel)
  1215. speaker by utilizing Pulse-Width-Modulation, which toggles the speaker faster
  1216. than it can physically move to simulate positions between fully on and fully
  1217. off.  There are several PD programs of this nature that I know of:
  1218.  
  1219. REMAC  - Plays MAC format sound files.  Files on the Macintosh, at least the
  1220.          sound files that I've ripped apart, seem to contain 3 parts.  The
  1221.          first two are info like what the file icon looks like and other
  1222.          header type info.  The third part contains the raw sample data, and
  1223.          it is this portion of the file which is saved to a seperate file,
  1224.          often named with the .snd extension by PC users.  Personally, I like
  1225.          to name the files .s1, .s2, .s3, or .s4 to indicate the sampling rate
  1226.          of the file. (-s# is how to specify the playback rate in REMAC.)
  1227.          REMAC provides playback rates of 5550hz, 7333hz, 11 khz, & 22 khz.
  1228. REMAC2 - Same as REMAC, but sounds better on higher speed machines.
  1229. REPLAY - Basically same as REMAC, but for playback of Atari ST sounds. 
  1230.          Apparently, the Atari has two sound formats, one of which sounds like
  1231.          garbage if played by REMAC or REPLAY in the incorrect mode.  The
  1232.          other file format works fine with REMAC and so appears to be 'normal'
  1233.          unsigned 8-bit data.  REPLAY provides playback rates of 11.5 khz,
  1234.          12.5 khz, 14 khz, 16 khz, 18.5 khz, 22khz, & 27 khz.
  1235.  
  1236. These three programs are all by the same author, Richard E. Zobell who does
  1237. not have an internet mail address to my knowledge, but does have a GEnie email
  1238. address of R.ZOBELL. 
  1239.  
  1240. Additionally, there are various stand-alone demos which use the internal
  1241. speaker, of which there is one called mushroom which plays a 30 second
  1242. advertising jingle for magic mushroom room deoderizers which is pretty
  1243. humerous.  I've used this player to playback samples that I ripped out of the
  1244. commercial game program Mean Streets, which uses something they call RealSound
  1245. (tm) to playback digital samples on the internal speaker. (Of course, I only do
  1246. this on my own system, and since I own the game, I see no problems with it.)
  1247.  
  1248. For owners of 8 Mhz 286's and above, the option to play 4 channel 8 bit sounds
  1249. (with decent quality) on the internal speaker is also a reality.  Quite a
  1250. number of PD programs exist to do this, including, but not limited to:
  1251.  
  1252. ModEdit, ModPlay, ScreamTracker, STM, Star Trekker, Tetra, and probably a few
  1253. more.  
  1254.  
  1255. All these programs basically make use of various sound formats used by the
  1256. Amiga line of computers.  These include .stm files, .mod files
  1257. [a.k.a. mod. files], and .nst files [really the same hing].  Also,
  1258. these programs pretty much all have the option to playback the 
  1259. sound to add-on hardware such as the SoundBlaster card, the Covox series of
  1260. devices, and also to direct the data to either one or two (for stereo)
  1261. parallel ports, which you could attach your own D/A's to.  (From what I have
  1262. seen, the Covox is basically an small amplified speaker with a D/A which plugs
  1263. into the parallel port.  This sounds very similiar to the Disney Sound System
  1264. (DSS) which people have been talking about recently.)  
  1265.  
  1266. ------------------------------------------------------------------------
  1267. The EA-IFF-85 documentation
  1268. ---------------------------
  1269.  
  1270. From: dgc3@midway.uchicago.edu
  1271.  
  1272. As promised, here's an ftp location for the EA-IFF-85 documentation.  It's
  1273. the November 1988 release as revised by Commodore (the last public release),
  1274. with specifications for IFF FORMs for graphics, sound, formatted text, and
  1275. more.  IFF FORMS now exist for other media, including structured drawing, and
  1276. new documentation is now available only from Commodore.
  1277.  
  1278. The documentation is at grind.isca.uiowa.edu [128.255.19.233], in the
  1279. directory /amiga/f1/ff185.  The complete file list is as follows:
  1280.  
  1281. DOCUMENTS.zoo    
  1282. EXAMPLES.zoo     
  1283. EXECUTABLE.zoo   
  1284. INCLUDE.zoo      
  1285. LINKER_INFO.zoo  
  1286. OBJECT.zoo       
  1287. SOURCE.zoo       
  1288. TP_IFF_Specs.zoo 
  1289.  
  1290. All files except DOCUMENTS.zoo are Amiga-specific, but may be used as a basis
  1291. for conversion to other platforms.  Well, I take that tentatively back.  I
  1292. don't know what TP_IFF_Specs.zoo contains, so it might be non-Amiga-specific.
  1293.  
  1294. ------------------------------------------------------------------------
  1295. US Federal Standard 1016 availability
  1296. -------------------------------------
  1297.  
  1298. From: Joe Campbell  N3JBC  jpcampb@afterlife.ncsc.mil  74040.305@compuserve.com
  1299.  
  1300. The U.S. DoD's Federal-Standard-1016 4800 bps code excited linear prediction
  1301. voice coder version 3.2 (CELP 3.2) Fortran and C simulation source codes are
  1302. now available for worldwide distribution at no charge (on DOS diskettes,
  1303. but configured to compile on Sun SPARC stations) from:
  1304.  
  1305. Bob Fenichel
  1306. National Communications System
  1307. Washington, D.C.  20305
  1308. 1-703-692-2124
  1309. 1-703-746-4960 (fax)
  1310.  
  1311. In addition to the source codes, example input and processed speech files
  1312. are included along with a technical information bulletin to assist in
  1313. implementation of FS-1016 CELP.  (An anonymous ftp site is being considered
  1314. for future releases.)
  1315.  
  1316. Copies of the FS-1016 document are available for $2.50 each from:
  1317.  
  1318. GSA Rm 6654
  1319. 7th & D St SW
  1320. Washington, D.C.  20407
  1321. 1-202-708-9205
  1322.  
  1323. The following articles describe the Federal-Standard-1016 4.8-kbps CELP
  1324. coder (it's unnecessary to read more than one):
  1325.  
  1326. Campbell, Joseph P. Jr., Thomas E. Tremain and Vanoy C. Welch,
  1327. "The Federal Standard 1016 4800 bps CELP Voice Coder," Digital Signal
  1328. Processing, Academic Press, 1991, Vol. 1, No. 3, p. 145-155.
  1329.  
  1330. Campbell, Joseph P. Jr., Thomas E. Tremain and Vanoy C. Welch,
  1331. "The DoD 4.8 kbps Standard (Proposed Federal Standard 1016),"
  1332. in Advances in Speech Coding, ed. Atal, Cuperman and Gersho,
  1333. Kluwer Academic Publishers, 1991, Chapter 12, p. 121-133.
  1334.  
  1335. Campbell, Joseph P. Jr., Thomas E. Tremain and Vanoy C. Welch, "The
  1336. Proposed Federal Standard 1016 4800 bps Voice Coder:  CELP," Speech
  1337. Technology Magazine, April/May 1990, p. 58-64.
  1338.  
  1339. For U.S. FED-STD-1016 (4800 bps CELP) _realtime_ DSP code
  1340. and information about products using this code, contact:
  1341.  
  1342. John DellaMorte
  1343. DSP Software Engineering
  1344. 165 Middlesex Tpk, Suite 206
  1345. Bedford, MA  01730
  1346. 1-617-275-3733
  1347. 1-617-275-4323 (fax)
  1348. dspse.bedford@channel1.com
  1349.  
  1350. DSP Software Engineering's code can run on a DSP Research's Tiger 30 board
  1351. (a PC board with a TMS320C3x and analog interface suited to development work)
  1352. or on Intellibit's AE2000 TMS320C31 based 3" by 2.5" card.
  1353.  
  1354. DSP Research                Intellibit
  1355. 1095 E. Duane Ave.          P.O. Box 9785
  1356. Sunnyvale, CA  94086        McLean, VA  22102-0785
  1357. (408)773-1042               (703)442-4781
  1358. (408)736-3451 (fax)         (703)442-4784 (fax)
  1359.  
  1360. From: tobiasr@monolith.lrmsc.loral.com (Richard Tobias )
  1361.  
  1362. For U.S. FED-STD-1016 (4800 bps CELP) _realtime_ DSP code and
  1363. information about products using this code using the AT&T DSP32C and
  1364. AT&T DSP3210, contact:
  1365.  
  1366. White Eagle Systems Technology, Inc.
  1367. 1123 Queensbridge Way
  1368. San Jose, CA 95120
  1369. (408) 997-2706
  1370. (408) 997-3584 (fax)
  1371. rjjt@netcom.com
  1372.  
  1373. ------------------------------------------------------------------------
  1374. Creative Voice (VOC) file format
  1375. --------------------------------
  1376.  
  1377. From: galt@dsd.es.com
  1378.  
  1379. (byte numbers are hex!)
  1380.  
  1381.     HEADER (bytes 00-19)
  1382.     Series of DATA BLOCKS (bytes 1A+) [Must end w/ Terminator Block]
  1383.  
  1384. - ---------------------------------------------------------------
  1385.  
  1386. HEADER:
  1387. =======
  1388.      byte #     Description
  1389.      ------     ------------------------------------------
  1390.      00-12      "Creative Voice File"
  1391.      13         1A (eof to abort printing of file)
  1392.      14-15      Offset of first datablock in .voc file (std 1A 00
  1393.                 in Intel Notation)
  1394.      16-17      Version number (minor,major) (VOC-HDR puts 0A 01)
  1395.      18-19      2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
  1396.  
  1397. - ---------------------------------------------------------------
  1398.  
  1399. DATA BLOCK:
  1400. ===========
  1401.  
  1402.    Data Block:  TYPE(1-byte), SIZE(3-bytes), INFO(0+ bytes)
  1403.    NOTE: Terminator Block is an exception -- it has only the TYPE byte.
  1404.  
  1405.       TYPE   Description     Size (3-byte int)   Info
  1406.       ----   -----------     -----------------   -----------------------
  1407.       00     Terminator      (NONE)              (NONE)
  1408.       01     Sound data      2+length of data    *
  1409.       02     Sound continue  length of data      Voice Data
  1410.       03     Silence         3                   **
  1411.       04     Marker          2                   Marker# (2 bytes)
  1412.       05     ASCII           length of string    null terminated string
  1413.       06     Repeat          2                   Count# (2 bytes)
  1414.       07     End repeat      0                   (NONE)
  1415.  
  1416.       *Sound Info Format:       **Silence Info Format:
  1417.        ---------------------      ----------------------------
  1418.        00   Sample Rate           00-01  Length of silence - 1
  1419.        01   Compression Type      02     Sample Rate
  1420.        02+  Voice Data
  1421.  
  1422.  
  1423.   Marker#           -- Driver keeps the most recent marker in a status byte
  1424.   Count#            -- Number of repetitions + 1
  1425.                          Count# may be 1 to FFFE for 0 - FFFD repetitions
  1426.                          or FFFF for endless repetitions
  1427.   Sample Rate       -- SR byte = 256-(1000000/sample_rate)
  1428.   Length of silence -- in units of sampling cycle
  1429.   Compression Type  -- of voice data
  1430.                          8-bits    = 0
  1431.                          4-bits    = 1
  1432.                          2.6-bits  = 2
  1433.                          2-bits    = 3
  1434.                          Multi DAC = 3+(# of channels) [interesting--
  1435.                                        this isn't in the developer's manual]
  1436.  
  1437. ------------------------------------------------------------------------
  1438. RIFF WAVE (.WAV) file format
  1439. ----------------------------
  1440.  
  1441. RIFF is a format by Microsoft and IBM which is similar in spirit and
  1442. functionality as EA-IFF-85, but not compatible (and it's in
  1443. little-endian byte order, of course :-).  WAVE is RIFF's equivalent of
  1444. AIFF, and its inclusion in Microsoft Windows 3.1 has suddenly made it
  1445. important to know about.
  1446.  
  1447. Rob Ryan was kind enough to send me a description of the RIFF format.
  1448. Unfortunately, it is too big to include here (27 k), but I've made it
  1449. available for anonymous ftp as ftp.cwi.nl:/pub/RIFF-format.
  1450.  
  1451. And here's a pointer to the official description from Matt Saettler,
  1452. Microsoft Multimedia:
  1453.  
  1454. "The complete definition of the WAVE file format as defined by
  1455. IBM/Microsoft is available for anon. FTP from ftp.uu.net in the
  1456. vendor/microsoft/multimedia directory."
  1457.  
  1458. (Rob Ryan's version may actually be an extract from one of the files
  1459. stored there.)
  1460.  
  1461. ------------------------------------------------------------------------
  1462. U-LAW and A-LAW definitions
  1463. ---------------------------
  1464.  
  1465. [Adapted from information provided by duggan@cc.gatech.edu (Rick
  1466. Duggan) and davep@zenobia.phys.unsw.EDU.AU (David Perry)]
  1467.  
  1468. u-LAW (really mu-LAW) is
  1469.  
  1470.           sgn(m)   (     |m |)       |m |
  1471.    y=    ------- ln( 1+ u|--|)       |--| =< 1
  1472.          ln(1+u)   (     |mp|)       |mp|         
  1473.  
  1474. A-LAW is
  1475.  
  1476.      |     A    (m )                 |m |    1
  1477.      |  ------- (--)                 |--| =< - 
  1478.      |  1+ln A  (mp)                 |mp|    A     
  1479.    y=|
  1480.      | sgn(m) (        |m |)    1    |m |
  1481.      | ------ ( 1+ ln A|--|)    - =< |--| =< 1
  1482.      | 1+ln A (        |mp|)    A    |mp|         
  1483.  
  1484. Values of u=100 and 255, A=87.6, mp is the Peak message value, m is
  1485. the current quantised message value.  (The formulae get simpler if you
  1486. substitute x for m/mp and sgn(x) for sgn(m); then -1 <= x <= 1.)
  1487.  
  1488. Converting from u-LAW to A-LAW is in a sense "lossy" since there are
  1489. quantizing errors introduced in the conversion.
  1490.  
  1491. "..the u-LAW used in North America and Japan, and the
  1492. A-LAW used in Europe and the rest of the world and
  1493. international routes.."
  1494.  
  1495. References:
  1496.  
  1497. Modern Digital and Analog Communication Systems, B.P.Lathi., 2nd ed.
  1498. ISBN 0-03-027933-X
  1499.  
  1500. Transmission Systems for Communications
  1501. Fifth Edition
  1502. by Members of the Technical Staff at Bell Telephone Laboratories
  1503. Bell Telephone Laboratories, Incorporated
  1504. Copyright 1959, 1964, 1970, 1982
  1505.  
  1506. ------------------------------------------------------------------------
  1507. AVR File Format
  1508. ---------------
  1509.  
  1510. From: hyc@hanauma.Jpl.Nasa.Gov (Howard Chu)
  1511.  
  1512. A lot of PD software exists to play Mac .snd files on the ST. One other
  1513. format that seems pretty popular (used by a number of commercial packages)
  1514. is the AVR format (from Audio Visual Research). This format has a 128 byte
  1515. header that looks like this:
  1516.  
  1517.         char magic[4]="2BIT";
  1518.         char name[8];           /* null-padded sample name */
  1519.         short mono;             /* 0 = mono, 0xffff = stereo */
  1520.         short rez;              /* 8 = 8 bit, 16 = 16 bit */
  1521.         short sign;             /* 0 = unsigned, 0xffff = signed */
  1522.         short loop;             /* 0 = no loop, 0xffff = looping sample */
  1523.         short midi;             /* 0xffff = no MIDI note assigned,
  1524.                                    0xffXX = single key note assignment
  1525.                                    0xLLHH = key split, low/hi note */
  1526.         long rate;              /* sample frequency in hertz */
  1527.         long size;              /* sample length in bytes or words (see rez) */
  1528.         long lbeg;              /* offset to start of loop in bytes or words.
  1529.                                    set to zero if unused. */
  1530.         long lend;              /* offset to end of loop in bytes or words.
  1531.                                    set to sample length if unused. */
  1532.         short res1;             /* Reserved, MIDI keyboard split */
  1533.         short res2;             /* Reserved, sample compression */
  1534.         short res3;             /* Reserved */
  1535.         char ext[20];           /* Additional filename space, used
  1536.                                    if (name[7] != 0) */
  1537.         char user[64];          /* User defined. Typically ASCII message. */
  1538.  
  1539. -----------------------------------------------------------------------
  1540. The Amiga MOD Format
  1541. --------------------
  1542.  
  1543. From: norlin@mailhost.ecn.uoknor.edu (Norman Lin)
  1544.  
  1545. MOD files are music files containing 2 parts:
  1546.  
  1547. (1) a bank of digitized samples
  1548. (2) sequencing information describing how and when to play the samples
  1549.  
  1550. MOD files originated on the Amiga, but because of their flexibility
  1551. and the extremely large number of MOD files available, MOD players
  1552. are now available for a variety of machines (IBM PC, Mac, Sparc
  1553. Station, etc.)
  1554.  
  1555. The samples in a MOD file are raw, 8 bit, signed, headerless, linear
  1556. digital data.  There may be up to 31 distinct samples in a MOD file,
  1557. each with a length of up to 128K (though most are much smaller; say,
  1558. 10K - 60K).  An older MOD format only allowed for up to 15 samples in
  1559. a MOD file; you don't see many of these anymore.  There is no standard
  1560. sampling rate for these samples.
  1561.  
  1562. The sequencing information in a MOD file contains 4 tracks of
  1563. information describing which, when, for how long, and at what frequency
  1564. samples should be played.  This means that a MOD file can have up
  1565. to 31 distinct (digitized) instrument sounds, with up to 4 playing
  1566. simultaneously at any given point.  This allows a wide variety
  1567. of orchestrational possibilities, including use of voice samples
  1568. or creation of one's own instruments (with appropriate sampling
  1569. hardware/software).  The ability to use one's own samples as instruments
  1570. is a flexibility that other music files/formats do not share, and
  1571. is one of the reasons MOD files are so popular, numerous, and diverse.
  1572.  
  1573. 15 instrument MODs, as noted above, are somewhat older than 31
  1574. instrument MODs and are not (at least not by me) seen very often
  1575. anymore.  Their format is identical to that of 31 instrument MODs
  1576. except:
  1577.  
  1578. (1) Since there are only 15 samples, the information for the last (15th)
  1579.     sample starts at byte 440 and goes through byte 469.
  1580. (2) The songlength is at byte 470 (contrast with byte 950 in 31 instrument
  1581.     MOD)
  1582. (3) Byte 471 appears to be ignored, but has been observed to be 127.
  1583.     (Sorry, this is from observation only)
  1584. (4) Byte 472 begins the pattern sequence table (contrast with byte 952
  1585.     in a 31 instrument MOD)
  1586. (5) Patterns start at byte 600 (contrast with byte 1084 in 31 instrument MOD)
  1587.  
  1588. "ProTracker," an Amiga MOD file creator/editor, is available for ftp
  1589. everywhere as pt??.lzh.
  1590.  
  1591. From: Apollo Wong <apollo@ee.ualberta.ca>
  1592.  
  1593. From: M.J.H.Cox@bradford.ac.uk (Mark Cox)
  1594. Newsgroups: alt.sb.programmer
  1595. Subject: Re: Format for MOD files...
  1596. Message-ID: <1992Mar18.103608.4061@bradford.ac.uk>
  1597. Date: 18 Mar 92 10:36:08 GMT
  1598. Organization: University of Bradford, UK
  1599.  
  1600. wdc50@DUTS.ccc.amdahl.com (Winthrop D Chan) writes:
  1601. >I'd like to know if anyone has a reference document on the format of the
  1602. >Amiga Sound/NoiseTracker (MOD) files. The author of Modplay said he was going
  1603. >to release such a document sometime last year, but he never did. If anyone
  1604.  
  1605. I found this one, which covers it better than I can explain it - if you
  1606. use this in conjunction with the documentation that comes with Norman
  1607. Lin's Modedit program it should pretty much cover it.
  1608.  
  1609. Mark J Cox
  1610.  
  1611. /***********************************************************************
  1612.  
  1613. Protracker 1.1B Song/Module Format:
  1614. -----------------------------------
  1615.  
  1616. Offset  Bytes  Description
  1617. ------  -----  -----------
  1618.    0     20    Songname. Remember to put trailing null bytes at the end...
  1619.  
  1620. Information for sample 1-31:
  1621.  
  1622. Offset  Bytes  Description
  1623. ------  -----  -----------
  1624.   20     22    Samplename for sample 1. Pad with null bytes.
  1625.   42      2    Samplelength for sample 1. Stored as number of words.
  1626.                Multiply by two to get real sample length in bytes.
  1627.   44      1    Lower four bits are the finetune value, stored as a signed
  1628.                four bit number. The upper four bits are not used, and
  1629.                should be set to zero.
  1630.                Value:  Finetune:
  1631.                  0        0
  1632.                  1       +1
  1633.                  2       +2
  1634.                  3       +3
  1635.                  4       +4
  1636.                  5       +5
  1637.                  6       +6
  1638.                  7       +7
  1639.                  8       -8
  1640.                  9       -7
  1641.                  A       -6
  1642.                  B       -5
  1643.                  C       -4
  1644.                  D       -3
  1645.                  E       -2
  1646.                  F       -1
  1647.  
  1648.   45      1    Volume for sample 1. Range is $00-$40, or 0-64 decimal.
  1649.   46      2    Repeat point for sample 1. Stored as number of words offset
  1650.                from start of sample. Multiply by two to get offset in bytes.
  1651.   48      2    Repeat Length for sample 1. Stored as number of words in
  1652.                loop. Multiply by two to get replen in bytes.
  1653.  
  1654. Information for the next 30 samples starts here. It's just like the info for
  1655. sample 1.
  1656.  
  1657. Offset  Bytes  Description
  1658. ------  -----  -----------
  1659.   50     30    Sample 2...
  1660.   80     30    Sample 3...
  1661.    .
  1662.    .
  1663.    .
  1664.  890     30    Sample 30...
  1665.  920     30    Sample 31...
  1666.  
  1667. Offset  Bytes  Description
  1668. ------  -----  -----------
  1669.  950      1    Songlength. Range is 1-128.
  1670.  951      1    Well... this little byte here is set to 127, so that old
  1671.                trackers will search through all patterns when loading.
  1672.                Noisetracker uses this byte for restart, but we don't.
  1673.  952    128    Song positions 0-127. Each hold a number from 0-63 that
  1674.                tells the tracker what pattern to play at that position.
  1675. 1080      4    The four letters "M.K." - This is something Mahoney & Kaktus
  1676.                inserted when they increased the number of samples from
  1677.                15 to 31. If it's not there, the module/song uses 15 samples
  1678.                or the text has been removed to make the module harder to
  1679.                rip. Startrekker puts "FLT4" or "FLT8" there instead.
  1680.  
  1681. Offset  Bytes  Description
  1682. ------  -----  -----------
  1683. 1084    1024   Data for pattern 00.
  1684.    .
  1685.    .
  1686.    .
  1687. xxxx  Number of patterns stored is equal to the highest patternnumber
  1688.       in the song position table (at offset 952-1079).
  1689.  
  1690. Each note is stored as 4 bytes, and all four notes at each position in
  1691. the pattern are stored after each other.
  1692.  
  1693. 00 -  chan1  chan2  chan3  chan4
  1694. 01 -  chan1  chan2  chan3  chan4
  1695. 02 -  chan1  chan2  chan3  chan4
  1696. etc.
  1697.  
  1698. Info for each note:
  1699.  
  1700.  _____byte 1_____   byte2_    _____byte 3_____   byte4_
  1701. /                \ /      \  /                \ /      \
  1702. 0000          0000-00000000  0000          0000-00000000
  1703.  
  1704. Upper four    12 bits for    Lower four    Effect command.
  1705. bits of sam-  note period.   bits of sam-
  1706. ple number.                  ple number.
  1707.  
  1708. Periodtable for Tuning 0, Normal
  1709.   C-1 to B-1 : 856,808,762,720,678,640,604,570,538,508,480,453
  1710.   C-2 to B-2 : 428,404,381,360,339,320,302,285,269,254,240,226
  1711.   C-3 to B-3 : 214,202,190,180,170,160,151,143,135,127,120,113
  1712.  
  1713. To determine what note to show, scan through the table until you find
  1714. the same period as the one stored in byte 1-2. Use the index to look
  1715. up in a notenames table.
  1716.  
  1717. This is the data stored in a normal song. A packed song starts with the
  1718. four letters "PACK", but i don't know how the song is packed: You can
  1719. get the source code for the cruncher/decruncher from us if you need it,
  1720. but I don't understand it; I've just ripped it from another tracker...
  1721.  
  1722. In a module, all the samples are stored right after the patterndata.
  1723. To determine where a sample starts and stops, you use the sampleinfo
  1724. structures in the beginning of the file (from offset 20). Take a look
  1725. at the mt_init routine in the playroutine, and you'll see just how it
  1726. is done.
  1727.  
  1728. Lars "ZAP" Hamre/Amiga Freelancers
  1729.  
  1730. ***********************************************************************/
  1731.  
  1732. -- 
  1733. Mark J Cox -----
  1734. Bradford, UK ---
  1735.  
  1736. -----------------------------------------------------------------------
  1737.